/**
 *
 */
package jp.takapy.baycity.util;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import android.util.Log;

/**
* xml操作に関連するUtilクラス
*
* @author hirop
*
*/
public class XMLUtils {

	private static String TAG = "BaycityBusApp.XMLUtils";

	/**
	* org.w3c.dom.DocumentをStringに変換する
	* 変換できなかったときはnullを返す
	* @param doc
	* @return string
	*/
	public static String document2String(Document doc) {

		String string = null;
		StringWriter writer = new StringWriter();
		StreamResult result = new StreamResult(writer);
		TransformerFactory factory = TransformerFactory.newInstance();

		Transformer former;
		try {
			former = factory.newTransformer();
			former.transform(new DOMSource(doc.getDocumentElement()), result);
			string = result.getWriter().toString();
		} catch (TransformerConfigurationException e) {
			Log.e(TAG, e.getMessage());

		} catch (TransformerException e) {
			Log.e(TAG, e.getMessage());
		}
		return string;
	}


}

